#include "Require/Init.iss"
#include "Class/${Me.Class}.iss"

function main()
{
	Turbo 1000
	extension -require isxeq
	EA "Loading" "Wanderbot.iss"

	InjectObject Core BotCore
	InjectObject Move Movement
	InjectObject Scan Scanning
	InjectObject Loot Looting
	InjectObject Activate Activating
	InjectObject Avatar Character
	InjectObject Idle BotIdle
	InjectObject Action BotAction

	declare MOVEFORWARD string script
	declare MOVEBACKWARD string script
	declare STRAFELEFT string script
	declare STRAFERIGHT string script
	declare TURNLEFT string script
	declare TURNRIGHT string script
	declare LogDir file script

	call LoadGUI
	call InitializeSettings
	BindTriggers
	Bind togglebot f1 ToggleBot

	Base:ClearTarget
	
	call Core.Run
}

function atexit()
{
	Move:Stop
	call StoreSettings
	call UnloadGUI
	Bind -delete togglebot
	EA "Unloading" "Wanderbot.iss"
}

atom(global) ToggleBot()
{
	if ${Core.CurrentState} == 3
	{
		Event[CORE_EVENT_PAUSE]:Execute[FALSE]
		UIElement[EQ Wanderbot].FindUsableChild[cmdStart,commandbutton]:SetText["Pause"]
	}
	else
	{
		Event[CORE_EVENT_PAUSE]:Execute[TRUE]
		UIElement[EQ Wanderbot].FindUsableChild[cmdStart,commandbutton]:SetText["Start"]
		Move:Stop
	}
}

atom InjectObject(string VariableName, string ObjectName)
{
	declare ${VariableName} ${ObjectName} global
	EA "${ObjectName}" "Injected into Wanderbot"
	${VariableName}:Inject
}